home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / rc-1.000 / rc-1 / rc-1.5-linux / LINUX_NOTES < prev    next >
Encoding:
Text File  |  1994-07-28  |  13.9 KB  |  283 lines

  1. Compilation of rc on Linux (kernel version 1.0+, libc-4.5.21+, gcc-2.5.8+)
  2. --------------------------------------------------------------------------
  3.  
  4. CHANGES FROM THE STOCK RC-1.5 DISTRIBUTION (AT viz.tamu.edu:/pub/rc)
  5.  
  6. (NOTE! syntactical changes are in no way condoned by the author Byron Rakitzis,
  7.        he wasn't even contacted.  DON'T BUG him about them.  There still exits
  8.        an rc mailing list for discussion of this kind of stuff.  READ THE FAQ!)
  9.  
  10.     0)  LITTLE THINGS:
  11.  
  12. ---->   defined the /dev/fd in config.h
  13. ---->   Linux has /proc, make a symbolic link: ln -s /proc/self/fd /dev/fd
  14. ---->   made sure READLINE was undefined, see line editing section below
  15. ---->   Also changed some optimization flags.
  16.  
  17.     1)  sigmsgs.[ch]
  18.  
  19.         A "non-standard" signal.h file causes 'mksignal' to completely fail.
  20.         To fix it we use the signal(7) man page to find the 29 signals and
  21.         their descriptions.  See my versions of sigmsgs.[ch] at the bottom
  22.         of this file.  I have left them in the directory and modified 'make
  23.         clean' to not trash them.
  24.  
  25.     2)  redundant declaration removal
  26.         
  27.         To get rc to compile I had to comment out the (redundant) declaration
  28.         of 'longjmp' in jbwrap.h and compile with SYSVR4 defined.
  29.  
  30.     3)  trip.rc notes
  31.  
  32.         rc so obtained passes all 'trip.rc' tests with the following exceptions:
  33.  
  34.             '. -i' doesn't print out prompts. (not big deal functionally)
  35.  
  36.             protect_env trip fails, but looking at a '-x' trace of what's going
  37.                 on seems to validate the behavior.  The command substitution
  38.                 should obviously return (), which it does.  ! ~ () '..' -> true
  39.                 so it fails.   I don't thing that the '!' should be there.
  40.                 But even if it were, since the function searched for is never
  41.                 defined, why would it ever be there?  This 'trip' seems broken.
  42.                 By the way, I've tested it other ways and 'rc -p' really does
  43.                 'protect' your environment from parent process function
  44.                 (but not variable) definitions.
  45.  
  46.     4)  builtin-cd silenced
  47.     
  48.         I commented out the statement which printf's the directory switched to
  49.         when builtin 'cd' has to resort to $CDPATH to find a directory.  If you
  50.         like this feature, just uncomment lines 160, 161 in builtins.c
  51.  
  52.         I have commented out these two trips so that all the others get tested.
  53.  
  54.     5)
  55.         I added several useful builtin functions to rc.  See below for a full
  56.         description.  *These are easily removed*.  I figured I should have 'em
  57.         in the binary distribution because the people most likely to despise
  58.         them would be better equipped to re-compile them out.  Those most likely
  59.         to leave them in either have no philosophical objection or are likely
  60.         to appreciate the extra stuff.
  61.  
  62. LINE EDITING ALTERNATIVES ****************************************************
  63.  
  64. ---->   To use the readline library you need to get the GNU readline library:
  65.             sunsite.unc.edu:/pub/Linux/libs/librl-2.0.tar.gz
  66.         Note that static linking with readline is probably not recommended
  67.         as the library is HUGE (over 3 times the size of plain 'rc') and makes
  68.         the (static) binary four times larger.  Dynamic linking doesn't change
  69.         the binary by more than a few bytes.  To compile with readline (or
  70.         editline) edit Makefile and config.h appropriately.  See the generic
  71.         unix instructions.
  72.  
  73. ---->   You can also use the 'editline' plug-in replacement for readline which
  74.         is distributed in the package for building sharable linux libraries,
  75.             sunsite.unc.edu:/pub/Linux/GCC/src/tools-2.11.gz
  76.         I haven't found it to edit as reliably as readline though.  It only
  77.         adds like 10K to the static binary though.  Maybe we should encourage
  78.         the author to make it a little stronger.
  79.  
  80. ---->   Yet another alternative is to get my very enhanced version of 'ile' for
  81.         Linux.  Traditionally pseudo-terminal front-ends have had a lot of
  82.         trouble tracking the working directory of the child application.
  83.         All that is over with the '/proc' filesystem.  /proc/PID/cwd is a
  84.         symbolic link to current working directory of the process.  The master
  85.         can just use the child's PID.  This information is maintained by the
  86.         kernel, and so the cwd obtained in this way *IS* the cwd (almost by
  87.         definition!).  The only times I've found this technique to fail was
  88.         in a 'su' shell, where the command just forks a copy of the current
  89.         shell.  ILE continues to look at the cwd of the original process.  This
  90.         might be fixable by modifying 'su', say to set an environment variable
  91.         in the initial process or something.  I've also added a forward history
  92.         search, and a few other things.  See the ILE package for full details.
  93.  
  94.         Additionally /proc/PID/environ allows the pseudo-terminal front-end
  95.         to allow configuration options via shell environment variables like
  96.         $FINGNORE.  I haven't yet implemented this stuff yet.
  97.  
  98. ---->   There are a few other pseudo-terminal front-ends (atty, fe, rkbd,..)
  99.         the first of which is purported to work well under Linux.  Try those
  100.         out as well, if you don't like ReadLine or ILE (Interactive Line Ed.).
  101.  
  102. NOTES ON MY ADDED BUILTINS ****************************************************
  103.  
  104. I altered the Makefile interface to builtins to understand all files of the
  105. form b_*.c to be addons.  You may have to change this to an explicit list
  106. if you don't have the GNU make. You also might change it to selectively remove
  107. some of my builtins.  I have NOT updated the rc man page to reflect these
  108. builtin commands.  For and explanation of what they do, see each b_*.c line
  109. below.
  110.  
  111. With no extra builtins, rc is 62468 bytes (dynamic) or 82948 (static).  With
  112. my builtins for test, expr, getopts, read, seq, ssub, it is 74756 bytes, only
  113. 12288 bytes or 20% larger.  The static binary becomes 115716 bytes, 32768 bytes
  114. or 40% larger.  Depending on the subset of builtins you want, you can make this
  115. binary size hit as small as desired.  Even with the kitchen sink, rc is still
  116. smaller than almost any other shell by a significant margin.  The only real
  117. competitor is ash.  Csh, ksh, bash, tcsh, zsh,...  don't even come close(unless
  118. you compile readline in statically!).
  119.  
  120. I ran some performance tests.  To do all kinds of stat()'s took only .06 sec
  121. real time with the builtin test, while it took over 1.9 sec real time for
  122. the exact same tests using an external program.  That's a factor of 30 folks.
  123. The improvement for builtin 'expr' isn't as spectacular, only a 2.25 fold
  124. increase in speed.  But still... Anyway, here's a brief description of my
  125. builtins.  Under the filename of each source I list its *individual*
  126. contribution to static and dynamic binary sizes.  Adding multiple builtins
  127. *does not* incur increasing the binary by the sum of these individual con-
  128. tributions because of padding out to page boundaries and joint use of the same
  129. library functions(string, stdio, etc).
  130.  
  131. b_expr.c Simple expr with buggy '(' handling.  Need to fix that.  Also
  132. 20480(s) doesn't do ':' mode.  As an external program under Linux this
  133. 4096(d)  is only 1.5K, while the GNU expr is over 35K.  Go figure.  I
  134.          don't think it's only because of ':' either ;-).  If desired
  135.          the static contribution of expr could be greatly diminished by
  136.          removin the "printf" reference.  An itoa() function would then
  137.          be needed.  Feel free.  Mail me the patch.
  138.  
  139. b_test.c Enhanced test.  Only real difference from the GNU test is that
  140. 4096(s)  there's a '-h' flag to tell you that a file has more than 1 hard
  141. 8192(d)  link.  And it's faster than the GNU test code by 5% or so (as an
  142.          external program, of course :-).  Also, in my test, the closing
  143.          ']' is optional.  Note also that if '=' isn't quoted, rc gets
  144.          confused.  This happens with all commands and external programs too,
  145.          e.g. 'dd'.
  146.  
  147. Both b_expr.c and b_test.c are set up to be made into external programs
  148. if compiled without ADDON defined, in case you want a *tiny* replacement for
  149. the GNU utilities, for say a boot/recovery floppy or something.
  150.  
  151. b_read.c The final, best builtin read from the rc mailing list.  Reads an
  152. 0(s)     entire line into a single variable.  If you want multiple variables,
  153. 0(d)     you can trivially write a 'Read' function to do the proper word
  154.          splitting and assignment.  The important thing about this builtin
  155.          is that it doesn't buffer it's input *at all*.  Also included in this
  156.          distribution is 'line.c', the source for a tiny external program that
  157.          can be combined with a shell function to achieve the same behavior
  158.          at a reduction in performance.  Note also that it doesn't add enough
  159.          bytes to either a dynamic *or* a static executable to add another
  160.          page of virtual memory!  The same is true for true and false below.
  161.          These builtins cost essentially *nothing* in size.
  162.  
  163. b_seq.c  is a builtin for the very commonly needed 'seqence of integers'
  164. 20930(s) function in 'rc' functions/scripts.  It's used to reference ranges
  165. 0(d)     of elements in a list, e.g. elements 2 to the end of 'hiho' might
  166.          be referenced by $hiho(`{seq 2 $#hiho}).  See source and rc-FAQ
  167.          for more info.
  168.  
  169. b_ssub.c is a builtin for the very frequent suffix/prefix substitution many
  170. 20480(s) of us are always doing.  E.g. we want a variable that contains
  171. 4096(d)  the names of all '.c' files with no matching '.h' files.
  172.          TheVar=`{for(x in *.c)! [ -f `{ssub $x .c .h} ]&&echo $x}
  173.          ssub can also to *prefix* substition (ssub -p) and path stripping
  174.          like basename (ssub -S).  See source for more info.
  175.  
  176. b_getopt.c Standard getopt utility to parse option arguments.  Basically this
  177. 28672(s)   just puts all options before a '--' so if you enter:
  178. 0(d)          'hiho -x junk -y more_junk arg1 -z still_more arg2 -egads'
  179.            getopt will return:
  180.               '-x junk -y more_junk -z still_more -e -g -a -d -s -- arg1 arg2'
  181.            getopt must have the getopt parse string as it's first argument and
  182.            the rest of the command line following it.  For the above example
  183.            this translates into:
  184.               'getopt x:y:z:egads $entered_command_line'
  185.            Note: ordinarily $* doesn't include argv[0], but you can if you
  186.                  want by using '$0 $*' were I have $entered_command_line.
  187.            The ':' indicates that the option takes an argument.
  188.            See any decent man page for getopt(3) or getopt(1) for more details.
  189.  
  190. b_true.c   These are self explanatory :-)
  191. 0(d or s)
  192. b_false.c  Well, OK.  They just return a status of true(0) or false(1).  This is
  193. 0(d or s)  a *really* intuitive thing in a script or function and adds minimal
  194.            overhead.  Only a few bytes really.  Not enough to change the size of
  195.            a demand paged binary.
  196.  
  197. It is *so* easy to remove these builtins that I'm including them by default for
  198. your enjoyment.  All you need to do to selectively remove one is comment out
  199. the two lines it's mentioned in in addon.h and "mv b_<builtin>.c B_<builtin>.c"
  200. (or "rm b_<builtin>.c" if you *really* hate it :-).
  201.  
  202. You don't even have to recompile the whole thing.  Just rename the b_<builtin>.c
  203. file and 'make'.  builtins.o is the only module which includes addon.h and the
  204. only module in which the _b_<builtin> symbol is referenced, so re-makes are fast.
  205.  
  206. To remove *all* the added builtins, uncomment out the '-DADDON' in the
  207. CFLAGS in the Makefile, rm builtin.o, and 'make'.
  208.  
  209. If you want to create your own builtins, it's *really* easy.  They have the
  210. form:
  211.  
  212. void b_foo(char* argv[]) {
  213.     ...
  214.     set(TRUE) or set(FALSE) (depending on what you want the exit status to be)
  215. }
  216.  
  217. I tried to add all of the functions that most shells seem to have builtin
  218. nowadays and the binary is still under 64K.  I realize that this is basically
  219. in *direct* opposition to the whole 'rc' philosophy (religion?), but
  220. what the hey, I like the 'rc' syntax and quoting rules.  I always thought
  221. the 'rc' philosophy had two major components: minimal syntax and minimal
  222. builtins.  I agree with the former while thinking the latter is at odds
  223. with significant performance and portability issues in shell script programming.
  224. No matter what happens with POSIX and all, you can just bet that some of the
  225. semantics of things like getopt, test, expr, etc. are going to be different on
  226. different unices.  Having a *core* set of *simple* one's in the shell is *not*
  227. an inherently evil idea.
  228.  
  229. In any case, I don't want to hear any flack that goes like 'How could you
  230. POSSIBLY add all those builtins to rc???!!!'.  If you don't like 'em,
  231. undefine ADDON and recompile.  I included them because I think a lot of people
  232. will find them icing on a well designed shell, perhaps enough to change over.
  233.  
  234. Charles Blake
  235. July 27, 1994
  236.  
  237.  
  238. Backups of Linux specific files.  Extract these to the filenames indicated if
  239. for some reason, they get clobbered/trashed.
  240.  
  241. ------- sigmsgs.c ----------
  242. #include "sigmsgs.h"
  243.  
  244. Sigmsgs signals[] = {
  245.     {"",""},
  246.     {"sighup","hangup"},
  247.     {"sigint",""},
  248.     {"sigquit","quit"},
  249.     {"sigill","illegal instruction"},
  250.     {"sigtrap","trace trap"},
  251.     {"sigabrt","abort instruction"},
  252.     {"sigunused","unused signal"},
  253.     {"sigfpe","floating point exception"},
  254.     {"sigkill","killed"},
  255.     {"sigusr1","user defined signal 1"},
  256.     {"sigsegv","segmentation violation"},
  257.     {"sigusr2","user defined signal 2"},
  258.     {"sigpipe",""},
  259.     {"sigalrm","alarm clock"},
  260.     {"sigterm","terminated"},
  261.     {"sigstkflt","stack fault"},
  262.     {"sigchld","child stop or exit"},
  263.     {"sigcont","continue"},
  264.     {"sigtstop","stopped"},
  265.     {"sigstp","stopped"},
  266.     {"sigttin","background tty read"},
  267.     {"sigttou","background tty write"},
  268.     {"sigio","input/output possible"},
  269.     {"sigxcpu","exceeded cpu time limit"},
  270.     {"sigxfsz","exceeded file size limit"},
  271.     {"sigvtalrm","virtual time alarm"},
  272.     {"sigprof","profiling time alarm"},
  273.     {"sigwinch","window changed"}
  274. };
  275.  
  276. ------ sigmsgs.h ------
  277.  
  278. typedef struct {
  279.     char *name, *msg;
  280. } Sigmsgs;
  281. extern Sigmsgs signals[];
  282. #define NUMOFSIGNALS 29
  283.